package org.huangrui.javase.api;

import java.lang.reflect.Field;
import java.util.StringJoiner;

/**
 * @Author hr
 * @Create 2025-11-07 10:15
 **/
public class T01StringModify {
    public static void main(String[] args) throws Exception {
        // stringJoiner();
        extracted();
    }

    /**
     * 反射有点问题要加入 VM 参数
     * --add-opens java.base/java.lang=ALL-UNNAMED
     * @throws Exception
     */
    private static void extracted() throws Exception {
        String str = "atguigu";
        Class<? extends String> clazz = str.getClass();
        Field valueField = clazz.getDeclaredField("value");
        valueField.setAccessible(true);
        byte[] value = (byte[]) valueField.get(str);
        value[0] = 'A';
        System.out.println(str);
    }

    private static void stringJoiner() {
        String[] arr = {"hello","world","java"};
        StringJoiner joiner = new StringJoiner("-","(",")");
        for (int i = 0; i < arr.length; i++) {
            joiner.add(arr[i]);
        }
        System.out.println(joiner);
        //(hello-world-java)
    }
}
